package com.zut.chat.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 礼物服务类
 */
@Slf4j
@Service
public class GiftService {

    /**
     * 礼物信息类
     */
    public static class Gift {
        private String name;
        private String icon;
        private String animation;
        private Integer value;
        private String description;

        public Gift(String name, String icon, String animation, Integer value, String description) {
            this.name = name;
            this.icon = icon;
            this.animation = animation;
            this.value = value;
            this.description = description;
        }

        // Getters
        public String getName() {
            return name;
        }

        public String getIcon() {
            return icon;
        }

        public String getAnimation() {
            return animation;
        }

        public Integer getValue() {
            return value;
        }

        public String getDescription() {
            return description;
        }
    }

    private final Map<String, Gift> giftMap = new HashMap<>();

    public GiftService() {
        initializeGifts();
    }

    /**
     * 初始化礼物列表
     */
    private void initializeGifts() {
        // 根据image目录中的SVGA文件初始化礼物
        addGift("666", "/image/666.png", "/image/666.svga", 66, "666大佬");
        addGift("LV包", "/image/LV包.png", "/image/LV包.svga", 520, "奢华LV包");
        addGift("天马", "/image/天马.png", "/image/天马.svga", 999, "天马行空");
        addGift("幸福马车", "/image/幸福马车.png", "/image/幸福马车.svga", 1314, "幸福马车");
        addGift("爱心气球", "/image/爱心气球.png", "/image/爱心气球.svga", 99, "爱心气球");
        addGift("爱心熊熊", "/image/爱心熊熊.png", "/image/爱心熊熊.svga", 199, "爱心熊熊");
        addGift("爱心直升机", "/image/爱心直升机.png", "/image/爱心直升机.svga", 888, "爱心直升机");
        addGift("爱的漂流瓶", "/image/爱的漂流瓶.png", "/image/爱的漂流瓶.svga", 299, "爱的漂流瓶");
        addGift("紫色城堡", "/image/紫色城堡.png", "/image/紫色城堡.svga", 2999, "紫色城堡");
        addGift("紫色玫瑰", "/image/紫色玫瑰.png", "/image/紫色玫瑰.svga", 188, "紫色玫瑰");
        addGift("红色跑车", "/image/红色跑车.png", "/image/红色跑车.svga", 1888, "红色跑车");
        addGift("财神到", "/image/财神到.png", "/image/财神到.svga", 6666, "财神到");
        addGift("超级火箭", "/image/超级火箭.png", "/image/超级火箭.svga", 9999, "超级火箭");
        addGift("钻石", "/image/钻石.png", "/image/钻石.svga", 5555, "钻石");

        log.info("初始化礼物列表完成，共 {} 个礼物", giftMap.size());
    }

    /**
     * 添加礼物
     */
    private void addGift(String name, String icon, String animation, Integer value, String description) {
        giftMap.put(name, new Gift(name, icon, animation, value, description));
    }

    /**
     * 获取所有礼物列表
     */
    public List<Gift> getAllGifts() {
        return new ArrayList<>(giftMap.values());
    }

    /**
     * 根据名称获取礼物
     */
    public Gift getGiftByName(String name) {
        return giftMap.get(name);
    }

    /**
     * 检查礼物是否存在
     */
    public boolean isValidGift(String name) {
        return giftMap.containsKey(name);
    }
}
